<template>
	<view class="pics">

		<scroll-view class="left" scroll-y="true">
			<view @click="handleClick(index,item.id)" :class="active===index?'active':''" v-for="(item,index) in leftData" :key='item.id'>{{item.title}}</view>
		</scroll-view>
		<scroll-view scroll-y="true" class="right">
			<view class="img" v-for="(item,index) in rightData" :key='item.id'>
				<image @click="preview(item.img_url)" :src="item.img_url" mode=""></image>
				<text>{{item.title}}</text>
<!-- <text v-if='rightData.length===0'>暂时缺少数据</text> -->
			</view>
			<text v-if='rightData.length===0'>暂时缺少数据</text>

		</scroll-view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				leftData: [],
				rightData: [],
				active: 0
			}
		},
		methods: {
			onLoad() {
				this.getLeftData()
			},
			//请求左边框下拉数据
			async getLeftData() {
				const res = await uni.request({
					url: 'http://localhost:8082/api/getimgcategory'
				})

				// console.log(res)
				let data = res[1].data
				// console.log(data)
				if (data.status !== 0) {
					return uni.showToast({
						title: '获取数据失败'
					})
				} else {
					this.leftData = data.message
					// console.log(this.leftData)
					this.handleClick(0, this.leftData[0].id)
				}

			},
			//鼠标点击左边下拉框事件
			async handleClick(index, id) {
				this.active = index
				//请求右边框下拉数据
				const res = await uni.request({
					url: 'http://localhost:8082/api/getimages/' + id

				})
				// console.log(res)
				const data = res[1].data
				if (data.status !== 0) {
					return uni.showToast({
						title: '获取右边框数据失败'
					})
				} else {
					this.rightData = data.message
					console.log(this.rightData)
				}
			},
			preview(current){
				const urls=this.rightData.map(item=>{
					return item.img_url
				})
				uni.previewImage({
					current,
					urls
				})
			}



		},
	}
</script>

<style lang="less">
	page {
		height: 100%;
	}

	.pics {
		display: flex;
		height: 100%;

		.left {
			height: 100%;
			width: 200rpx;

			view {
				width: 190rpx;
				height: 60px;
				text-align: center;
				line-height: 60px;
				border-top: 1px solid #ccc;
				border-right: 1px solid #ccc;
			}

			.active {
				background: #b50e03;
				color: #eee;
			}
		}

		.right {
			width: 100%;
			height: 100%;

			.img {
				margin: 10px 10px;

				image {
					width: 100%;


					height: 520rpx;
				}

				text {
					font-size: 35rpx;
					line-height: 50rpx;
				}

			}

		}
	}
</style>
